<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        #container{
            background: brown;
            height: 9999px;
        }
        #toTop{
            height: 50px;
            width: 50px;
            background: salmon;
            position: fixed;
            right: 50px;
            bottom: 100px;
            display: none;
            color: #ffffff;
            font-size:30px;
            text-align: center;
            border-radius:10%;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div id="container"></div>
<div id="toTop">↑</div>
<script>

    var t = document.querySelector("#toTop");
    window.onscroll = function () {
        console.log(document.documentElement.scrollTop > 1000 || document.body.scrollTop > 1000);
        if(document.documentElement.scrollTop > 1000 || document.body.scrollTop > 1000){
            t.style.display = "block";
        }else{
            t.style.display = "none";
        }
    }


    t.addEventListener('click',function () {
        window.scrollTo({
            top:0,
            behavior:'smooth'
        })
    });


</script>
</body>
</html>